package com.yami.shop.webservice.api.controller;



import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.mail.MailException;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yami.shop.bean.model.PersonNftApply;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.DataWebService;
import com.yami.shop.common.util.Json;
import com.yami.shop.common.util.ParamSignUtil;
import com.yami.shop.config.ShopConfig;
import com.yami.shop.personnft.common.service.PersonNftApplyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.*;

/**
 *
 * @ClassName:
 * @Description: 业务接口
 * @Author:
 * @Date: 2
 * @History 修改描述
 */
@RestController
@RequestMapping( "/outTranfer")
public class TranferApplyOutController {
	private final Logger log = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private PersonNftApplyService personNftApplyService;
	@Autowired
	private DataWebService dataWebService;
	@Autowired
	private ShopConfig shopConfig;
	/**
	 *
	 * @param
	 * @return
	 * @description: 下游转增接受通知
	 */
	@RequestMapping( "/outTranferApply")
	@ResponseBody
	public ServerResponseEntity outTranferApply(@Valid @RequestBody Map<String,Object> jSONObject) {
		Map<String,Object> hashMap = new HashMap<>();
		try {
			log.info("下游转增接受通知：" + Json.toJsonString(jSONObject));
			dataWebService.checkSign(jSONObject,hashMap,null);
			PersonNftApply personNftApply = new PersonNftApply();
			personNftApply.setDownApplyId(hashMap.get("id").toString());
			personNftApply.setStatus(Integer.valueOf(hashMap.get("status").toString()));
			personNftApplyService.updateByDownApplyId(personNftApply);
			return ServerResponseEntity.success();
		} catch (MailException e) {
			e.printStackTrace();
			log.error("下游转增接受通知异常: " + e.getMessage() + "\r\n" + Arrays.toString(e.getStackTrace()));
			return ServerResponseEntity.showFailMsg("通知异常");
		}catch (Exception e){
			log.error("通知异常: " + e.getMessage() + "\r\n" + Arrays.toString(e.getStackTrace()));
			return ServerResponseEntity.showFailMsg(e.getMessage());
		}
	}

}
